//
//  SysInfoVC.m
//  easyTaxi
//
//  Created by ellenpage on 13-1-23.
//  Copyright (c) 2013年 ellenpage. All rights reserved.
//

#import "SysInfoVC.h"
#import "Constant.h"
#import "PassValueClass.h"
#import "SocketObject.h"
#import "RequestCMD.h"
#import "Constant.h"

@interface SysInfoVC ()<UITableViewDataSource,UITableViewDelegate>

@property (weak, nonatomic)   IBOutlet UITableView *mTBView;
@property (strong, nonatomic) IBOutlet UIView *detailView;
@property (weak, nonatomic)   IBOutlet UIView *detailView_Small;
@property (weak, nonatomic)   IBOutlet UILabel *publishTimeLbl;
@property (weak, nonatomic)   IBOutlet UILabel *outTimeLbl;
@property (weak, nonatomic)   IBOutlet UITextView *contentTxtView;
@property (retain, nonatomic) NSMutableArray *dataArray;

- (IBAction)goBack;

- (IBAction)hideDetaiView;

@end

@implementation SysInfoVC

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self initialData];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

- (IBAction)goBack
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)hideDetaiView
{
    _detailView.hidden = YES;
}

- (void)viewDidUnload
{
    [self setMTBView:nil];
    [self setDetailView:nil];
    [self setDetailView_Small:nil];
    [self setMTBView:nil];
    [self setPublishTimeLbl:nil];
    [self setOutTimeLbl:nil];
    [self setContentTxtView:nil];
    [super viewDidUnload];
}

- (void)viewWillAppear:(BOOL)animated
{
    [_mTBView deselectRowAtIndexPath:[_mTBView indexPathForSelectedRow] animated:YES];

    _dataArray = [NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults] objectForKey:kMsmListArray]];
    [_mTBView reloadData];
}

- (void)initialData
{
    _detailView.backgroundColor = [[UIColor darkTextColor] colorWithAlphaComponent:0.65];
    [_detailView_Small.layer setCornerRadius:10];
    [_detailView_Small.layer setBorderColor:[[UIColor whiteColor] CGColor]];//描边颜色
    [_detailView_Small.layer setBorderWidth:2.0];//描边粗细
    [self.view addSubview:_detailView];
    _detailView.hidden = YES;
    
    _dataArray = [NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults] objectForKey:kMsmListArray]];
    NSLog(@"_dataArray = %@",_dataArray);
    _mTBView.delegate = self;
    _mTBView.dataSource = self;
    
    //--------------------1070---系统消息
    NSString *string    = [RequestCMD requestCMD:kSysInfo];
    NSMutableData *data = [RequestCMD getWantedData:string];
    [[SocketObject sharedInstance].gcdSocket writeData:data withTimeout:-1 tag:kSysInfo];//1035---预约打车
}


#pragma mark - TableView DataSource - 数据源

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
{
    return [_dataArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleBlue;
    }
    
    NSDictionary *dict  = [_dataArray objectAtIndex:indexPath.row];
    
    NSString *str = [dict objectForKey:kMsmTitle];
    NSString *idStr = [dict objectForKey:kMsmId];
    NSString *newStr = [NSString stringWithFormat:@"%@ 编号:%@",str,idStr];
    cell.textLabel.text = newStr;

    return cell;
}

#pragma mark - TableView Delegate   - 结构
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    int rowInt = [indexPath row];
    
    _detailView.tag = rowInt;
    _detailView.hidden = NO;
    
    NSDictionary *dict  = [_dataArray objectAtIndex:indexPath.row];
    
    NSString *contentStr     = [dict objectForKey:kMsmContent];
    NSString *publishTimeStr = [dict objectForKey:kMsmPublishTime];
    NSString *outTimeStr     = [dict objectForKey:kMsmOutTime];

    _contentTxtView.text = contentStr;
    _publishTimeLbl.text = publishTimeStr;
    _outTimeLbl.text     = outTimeStr;
}


@end
